import 'package:equatable/equatable.dart';

/// 用户关注模型
/// 使用Equatable实现相等性比较
class FollowModel extends Equatable {
  /// 关注关系ID
  final String id;

  /// 关注者用户ID
  final String followerId;

  /// 被关注者用户ID
  final String followingId;

  /// 关注时间
  final DateTime followTime;

  /// 是否互相关注
  final bool isMutual;

  const FollowModel({
    required this.id,
    required this.followerId,
    required this.followingId,
    required this.followTime,
    this.isMutual = false,
  });

  /// 从JSON创建关注对象
  factory FollowModel.fromJson(Map<String, dynamic> json) {
    return FollowModel(
      id: json['id'] as String,
      followerId: json['followerId'] as String,
      followingId: json['followingId'] as String,
      followTime: DateTime.parse(json['followTime'] as String),
      isMutual: json['isMutual'] as bool? ?? false,
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'followerId': followerId,
      'followingId': followingId,
      'followTime': followTime.toIso8601String(),
      'isMutual': isMutual,
    };
  }

  /// 复制并修改部分属性
  FollowModel copyWith({
    String? id,
    String? followerId,
    String? followingId,
    DateTime? followTime,
    bool? isMutual,
  }) {
    return FollowModel(
      id: id ?? this.id,
      followerId: followerId ?? this.followerId,
      followingId: followingId ?? this.followingId,
      followTime: followTime ?? this.followTime,
      isMutual: isMutual ?? this.isMutual,
    );
  }

  @override
  List<Object?> get props => [
    id,
    followerId,
    followingId,
    followTime,
    isMutual,
  ];

  @override
  String toString() {
    return 'FollowModel(id: $id, followerId: $followerId, followingId: $followingId, followTime: $followTime, isMutual: $isMutual)';
  }
}
